import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-06
 * Time: 15:27
 */
public class Test31 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int val) {
            this.val = val;
            next = null;
        }
        ListNode() {

        }
    }


    public static ListNode reverseKGroup(ListNode head, int k) {
        int count = 0;
        ListNode cur = head;
        while(cur != null) {
            count++;
            cur = cur.next;
        }
        // 翻转次数
        int n = count / k;

        ListNode newHead = new ListNode();
        ListNode pre = newHead;
        cur = head;

        for(int i = 0; i < n; i++) {
            ListNode tmp = cur;
            for(int j = 0; j < k; j++) {
                //头插法
                ListNode curNext = cur.next;
                cur.next = pre.next;
                pre.next = cur;
                cur = curNext;
            }
            pre = tmp;
        }
        pre.next = cur;
        return newHead.next;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ListNode head = null, tail = null;
        int n = sc.nextInt();
        for(int i = 0; i < n; i++) {
            int val = sc.nextInt();
            ListNode node = new ListNode(val);
            if(head == null) {
                head = node;
            } else {
                tail.next = node;
            }
            tail = node;
        }
        int k = sc.nextInt();
        ListNode ret = reverseKGroup(head,k);
        while(ret != null) {
            System.out.print(ret.val + " ");
            ret = ret.next;
        }
    }
}
